/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * 
 * @author Martin Mohr Pedersen
 */
public class SaleTest {

	private Sale sale;
	private Item item1;
	private Item item2;

	public SaleTest() {

	}

	@BeforeClass
	public static void setUpClass() throws Exception {
	}

	@AfterClass
	public static void tearDownClass() throws Exception {
	}

	@Before
	public void setUp() {
		sale = new Sale();
		item1 = new Item();
		item2 = new Item();
		item1.setItemNo("1");
		item2.setItemNo("2");
		item1.setPrice(50);
		item2.setPrice(200);
	}

	@After
	public void tearDown() {
	}

	/**
	 * Test of addItem method, of class Sale.
	 */
	@Test
	public void testAddItem() {

		assertFalse(sale.containsItem(item1));
		sale.addItem(item1, 1);
		assertTrue(sale.containsItem(item1));

		SaleLineItem line = sale.getLineForItem(item1);
		assertEquals(1, line.getQty());

		sale.addItem(item1, 2);
		line = sale.getLineForItem(item1);
		assertEquals(3, line.getQty());

	}
        @Test
        public void testAddNegativeItem()  {
                
                sale.addItem(item1, -1);
                assertTrue(sale.getTotal() < 0);
                
        }
        

}
